package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Tel       string `gorm:"type:varchar(20);not null"`
	Password  string `gorm:"type:char(32);not null"`
	HeadImage string `gorm:"type:varchar(500);not null"`
	NickName  string `gorm:"type:varchar(30);not null"`
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserByTel(db *gorm.DB, tel string) error {
	return db.Debug().Where("tel=?", tel).Find(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}
